/**
 * 
 */
package com.easidea.tim.entity.inventory;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springside.core.dao.extend.Undeletable;

import com.easidea.tim.entity.BaseEntity;
import com.easidea.tim.entity.commodity.Product;

/**
 * 
 * @author Harrison
 *
 */
@Entity(name="tim_inventory_storage")
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Cache(region="tim_inventory_storage",usage=CacheConcurrencyStrategy.READ_WRITE)
@Undeletable(status="deleted")
public class Storage extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8600620756504509272L;

	private Product product;
	private Double meterNum; // 米数
	private String name; // 名称
	private Boolean sampleFlag; // 剪样
	private Boolean chargeFlag; // 是否已填充
	private String chargedFlowNo; // 填充的销售单号
	
	/**
	 * @return the product
	 */
	@ManyToOne(fetch=FetchType.EAGER,optional=false)
	@JoinColumn(name="product_id")
	public Product getProduct() {
		return product;
	}
	/**
	 * @param product the product to set
	 */
	public void setProduct(Product product) {
		this.product = product;
	}
	/**
	 * @return the meterNum
	 */
	@Column(name="meter_num",length=10,precision=2, nullable=false)
	public Double getMeterNum() {
		return meterNum;
	}
	/**
	 * @param meterNum the meterNum to set
	 */
	public void setMeterNum(Double meterNum) {
		this.meterNum = meterNum;
	}
	/**
	 * @return the name
	 */
	@Column(name="name",nullable=false)
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the sampleFlag
	 */
	@Column(name="sample_flag", columnDefinition=" bool default false")
	public Boolean getSampleFlag() {
		return sampleFlag;
	}
	/**
	 * @param sampleFlag the sampleFlag to set
	 */
	public void setSampleFlag(Boolean sampleFlag) {
		this.sampleFlag = sampleFlag;
	}
	/**
	 * @return the chargedFlowNo
	 */
	@Column(name="charged_flow_no",nullable=true)
	public String getChargedFlowNo() {
		return chargedFlowNo;
	}
	/**
	 * @param chargedFlowNo the chargedFlowNo to set
	 */
	public void setChargedFlowNo(String chargedFlowNo) {
		this.chargedFlowNo = chargedFlowNo;
	}
	/**
	 * @return the chargeFlag
	 */
	@Column(name="charge_flag",columnDefinition="bool default false")
	public Boolean getChargeFlag() {
		return chargeFlag;
	}
	/**
	 * @param chargeFlag the chargeFlag to set
	 */
	public void setChargeFlag(Boolean chargeFlag) {
		this.chargeFlag = chargeFlag;
	}
	
	
	/* (non-Javadoc)
	 * @see com.easidea.tim.entity.BaseEntity#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
		      return true;
		
	    if (!(obj instanceof Storage))
	      return false;
	    
	    Storage tmp = (Storage) obj;
	    
	    return (this.product != null && tmp.product != null ) 
	    	&& (this.product.getId().equals(tmp.getProduct().getId()))? 
	    			this.meterNum.equals(tmp.getMeterNum()) &&
					this.sampleFlag.equals(tmp.getSampleFlag())
				: false;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		int hash = 1;
	    hash = hash * 31 
	                + (this.product == null ? 0 : this.product.hashCode());
	    hash = hash * 31 
	    			+ (this.meterNum == null ? 0 : this.meterNum.hashCode());
	    hash = hash * 31 
					+ (this.sampleFlag == null ? 0 : this.sampleFlag.hashCode());
	    hash = hash * 31 
					+ (this.chargeFlag == null ? 0 : this.chargeFlag.hashCode());
	    return hash;

	}
}
